package com.lishe.lishe.lishe.module.excitation.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.asynchttp.LSWebHelper;
import com.lishe.lishe.autoScrollListView.AutoScrollAdapter;
import com.lishe.lishe.autoScrollListView.AutoScrollListView;
import com.lishe.lishe.lishe.base.BaseFragment;
import com.lishe.lishe.lishe.http.HttpUser;
import com.lishe.lishe.lishe.module.commonclass.WebActivity;
import com.lishe.lishe.lishe.module.excitation.activity.CompanyConfirmActivity;
import com.lishe.lishe.lishe.module.excitation.activity.CompanyListActivity;
import com.lishe.lishe.lishe.module.excitation.activity.ExcitationActivity0;
import com.lishe.lishe.lishe.module.excitation.activity.JoinCompanyActivity;
import com.lishe.lishe.lishe.module.excitation.activity.PersonMessageComNameActivity;
import com.lishe.lishe.lishe.module.excitation.activity.PersonMessageModifyActivity;
import com.lishe.lishe.lishe.common.Globals;
import com.lishe.lishe.lishe.module.excitation.activity.MineWelfareActivity;
import com.lishe.lishe.lishe.module.excitation.activity.SignOutCompanyActivity;
import com.lishe.lishe.lishe.module.excitation.adapter.HeadScrollViewAdapter;
import com.lishe.lishe.lishe.module.excitation.bean.EncourageObject;
import com.lishe.lishe.lishe.module.excitation.bean.HeadInfo;
import com.lishe.lishe.lishe.module.excitation.bean.WelfareMessageObject;
import com.lishe.lishe.lishe.module.excitation.bean.company.CompanyInfo;
import com.lishe.lishe.lishe.module.excitation.bean.user.UserObject;
import com.lishe.lishe.lishe.module.excitation.dialog.ViewpagerDialog;
import com.lishe.lishe.lishe.module.excitation.presenter.ExcitationPresenter;
import com.lishe.lishe.lishe.module.main.activity.MainActivity0;
import com.lishe.lishe.lishe.module.me.http.HttpUserCenter;
import com.lishe.lishe.lishe.utils.SharedPreferencesUtils;
import com.lishe.lishe.lishe.utils.LoadingUtils;
import com.lishe.lishe.lishe.utils.Utils;
import com.lishe.lishe.lishe.widget.CircleImageView;
import com.lishe.lishe.retrofit.BaseDataPageBody;
import com.lishe.lishe.retrofit.DataResponseListener;
import com.lishe.lishe.retrofit.bean.InfoArrayObject;
import com.lishe.lishe.retrofit.presenter.BaseInfoBody;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import cz.msebera.android.httpclient.Header;

/**
 * Created by shino on 2017/11/20.
 * 企业首页
 */

public class ExcitationFragment extends BaseFragment implements View.OnClickListener {

    private LinearLayout mineFuLiLayout;
    private LinearLayout headInfoLayout;
    private LinearLayout teamExcitationLayout;
    private ImageView companyImage;
    private ImageView userImage;
    private TextView companyName;
    private TextView userName;
    private TextView userJob;
    private TextView welfareInfo;
    private TextView logoName;
    private ViewFlipper viewFlipper;

    private TextView headEmpty;
    private TextView teamEmpty;
    private RelativeLayout personLayout;
    private AutoScrollListView autoScrollListView;
    private AutoScrollListView headautoScrollListView;
    private LinearLayout mLinearAddCompany;
    private ViewStub mViewStub;
    private LinearLayout mLinearContent;

    private AutoScrollAdapter autoAdapter = null;
    private List<CompanyInfo> companys = new ArrayList<>();
    private List<HeadInfo> inFoObjectsHead = new ArrayList<>();
    private List<EncourageObject> inFoObjectsTeam = new ArrayList<>();
    private List<WelfareMessageObject> welfareMessageObjects = new ArrayList<>();
    private ImageLoaderUtils imageLoaderUtils;
    private DisplayImageOptions options0;
    private DisplayImageOptions options1;
    private View view;
    private HeadScrollViewAdapter headScrollViewAdapter = null;


    private UserObject userObject;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        imageLoaderUtils = new ImageLoaderUtils();
        options0 = imageLoaderUtils.setOptionsImage(R.drawable.defalut_img);
        options1 = imageLoaderUtils.setOptionsImage(R.mipmap.head);

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.fragment_excitation, null);
            initView(view);
        }
        view.setOnTouchListener(this);
        return view;
    }

    private void initView(View v) {
        mineFuLiLayout = v.findViewById(R.id.mine_fuli_layout);
        personLayout = v.findViewById(R.id.personLayout);
        headInfoLayout = v.findViewById(R.id.head_info_layout);
        teamExcitationLayout = v.findViewById(R.id.excitation_layout);
        companyImage = v.findViewById(R.id.company_image);
        userImage = v.findViewById(R.id.user_image);
        companyName = v.findViewById(R.id.company_name);
        userName = v.findViewById(R.id.user_name);
        userJob = v.findViewById(R.id.user_job);
        welfareInfo = v.findViewById(R.id.welfare_content);
        headEmpty = v.findViewById(R.id.head_empty);
        teamEmpty = v.findViewById(R.id.team_empty);
        logoName = v.findViewById(R.id.logo_name);
        viewFlipper = v.findViewById(R.id.viewfilper);
        viewFlipper.setVisibility(View.GONE);
        headautoScrollListView = v.findViewById(R.id.head_listView);
        autoScrollListView = v.findViewById(R.id.excitation_listView);
        headautoScrollListView.stopAutoScroll();
        autoScrollListView.stopAutoScroll();
        mLinearAddCompany = v.findViewById(R.id.ll_add_company);
        mViewStub = v.findViewById(R.id.view_stub);
        mLinearContent = v.findViewById(R.id.content);
        setListener();
    }

    private void setListener() {
        mineFuLiLayout.setOnClickListener(this);
        headInfoLayout.setOnClickListener(this);
        teamExcitationLayout.setOnClickListener(this);
        companyImage.setOnClickListener(this);
        userImage.setOnClickListener(this);
        headEmpty.setOnClickListener(this);
        teamEmpty.setOnClickListener(this);
        logoName.setOnClickListener(this);
        personLayout.setOnClickListener(this);


        headautoScrollListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                createHeadInfoDilog(position);
            }
        });
        autoScrollListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                ExcitationActivity0.jump(getActivity());
            }
        });
    }

    private void initData() {
        if (userObject != null) {
            if (TextUtils.isEmpty(userObject.getComId()) || userObject.getComId().equals("-1") || ((!userObject.getComId().equals("-1")) && !userObject.getEmpStatus().equals("1")) || ((!TextUtils.isEmpty(userObject.getEmpType())) && userObject.getEmpType().equals("6"))) {
                //comId 为-1时 表示未加入企业，comId 不等于 -1 时 empStatus = -1 标识未确认 1标示 已确认
                isInitCompany();
            } else {
                mLinearAddCompany.setVisibility(View.VISIBLE);
                mLinearContent.setBackgroundColor(getResources().getColor(R.color.normal_bg));
                if (viewNoCompany != null) {
                    viewNoCompany.setVisibility(View.GONE);
                }

                if (TextUtils.isEmpty(userObject.getComLogoPath())) {
                    logoName.setText(userObject.getComName());
                    companyImage.setVisibility(View.INVISIBLE);
                    logoName.setVisibility(View.VISIBLE);
                } else {
                    logoName.setVisibility(View.GONE);
                    companyImage.setVisibility(View.VISIBLE);
                    imageLoaderUtils.displayImage(userObject.getComLogoPath(), companyImage, options0);
//                    imageLoaderUtils.setImageBitmap(userObject.getComLogoPath(),companyImage);
                }
                imageLoaderUtils.displayImage(userObject.getUserAvatarPath(), userImage, options1);
                companyName.setText(userObject.getComName());
                userName.setText(userObject.getEmpName());
                String pos;
                String Dep;
                if (TextUtils.isEmpty(userObject.getPosName())) {
                    pos = "";
                } else {
                    pos = userObject.getPosName();
                }
                if (TextUtils.isEmpty(userObject.getDeptName())) {
                    Dep = userObject.getComName();
                } else {
                    Dep = userObject.getDeptName();
                }
                if (!TextUtils.isEmpty(userObject.getPosName()) && !TextUtils.isEmpty(userObject.getDeptName())) {
                    userJob.setText(Dep + "·" + pos);
                } else {
                    userJob.setText(Dep + pos);
                }
                if (Integer.valueOf(userObject.getWelfareCount()) > 0) {
                    String str = "共" + userObject.getWelfareCount() + "条关怀记录";
                    SpannableString spannableString = new SpannableString(str);
                    spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color4138)), 1, 1 + userObject.getWelfareCount().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    welfareInfo.setText(spannableString);
                } else {
                    welfareInfo.setText("共0条关怀记录");
                }
            }
        } else {//没有任何数据时的处理

        }
    }

    /**
     * 获取福利消息
     */
    private void getWelfareMessage() {
        ExcitationPresenter.getInstance().getAppWelfareList(Globals.getToken(), new DataResponseListener<BaseDataPageBody>() {
            @Override
            public void onSuccess(BaseDataPageBody dataResponse) {
                welfareMessageObjects.clear();
                Log.e("福利消息数量", dataResponse.getInfo().size() + "");
                welfareMessageObjects.addAll(dataResponse.getInfo());
                showViewFilper();
            }

            @Override
            public void onFail(String failMessage) {

            }

            @Override
            public void onError(Throwable e) {

            }
        });
    }

    /**
     * 是否加入企业
     * <p>
     * Spanned.SPAN_INCLUSIVE_EXCLUSIVE 从起始下标到终了下标，包括起始下标
     * Spanned.SPAN_INCLUSIVE_INCLUSIVE 从起始下标到终了下标，同时包括起始下标和终了下标
     * Spanned.SPAN_EXCLUSIVE_EXCLUSIVE 从起始下标到终了下标，但都不包括起始下标和终了下标
     * Spanned.SPAN_EXCLUSIVE_INCLUSIVE 从起始下标到终了下标，包括终了下标,包括起始下标
     */

    View viewNoCompany;

    private void isInitCompany() {
        mLinearContent.setBackgroundColor(getResources().getColor(R.color.white));

        if (viewNoCompany == null) {
            viewNoCompany = mViewStub.inflate();
        } else {
            viewNoCompany.setVisibility(View.VISIBLE);
        }
        //用户信息
        LinearLayout ll_user_info = viewNoCompany.findViewById(R.id.ll_user_info);
        CircleImageView head = viewNoCompany.findViewById(R.id.head_no_company);
        TextView name = viewNoCompany.findViewById(R.id.user_name_no_company);

        //查看申请
        LinearLayout check_my_apply = viewNoCompany.findViewById(R.id.check_my_apply);
        TextView company_no_company = viewNoCompany.findViewById(R.id.company_no_company);
        TextView look_my_reply = viewNoCompany.findViewById(R.id.look_my_reply);

        //申请加入公司
        LinearLayout join_my_company = viewNoCompany.findViewById(R.id.join_my_company);
        TextView joinCompany = viewNoCompany.findViewById(R.id.join_company_no_add_company);

        //离职
        LinearLayout ll_departure = viewNoCompany.findViewById(R.id.ll_departure);
        TextView departure_company = viewNoCompany.findViewById(R.id.departure_company);
        TextView departure_known = viewNoCompany.findViewById(R.id.departure_known);

        //审核不通过
        LinearLayout ll_apply_no_through = viewNoCompany.findViewById(R.id.ll_apply_no_through);
        TextView through_company = viewNoCompany.findViewById(R.id.through_company);
        TextView through_look_reply = viewNoCompany.findViewById(R.id.through_look_reply);


        joinCompany.setOnClickListener(this);
        look_my_reply.setOnClickListener(this);
        head.setOnClickListener(this);
        head.setOnClickListener(this);
        through_look_reply.setOnClickListener(this);
        departure_known.setOnClickListener(this);
        if (userObject != null) {

            imageLoaderUtils.displayImage(userObject.getUserAvatarPath(), head, options1);
            company_no_company.setText(getString(R.string.your_apply_join) + userObject.getComName());
            through_company.setText(getString(R.string.your_apply_join) + userObject.getComName());
            departure_company.setText(getString(R.string.your_has_from) + userObject.getComName());
            name.setText(userObject.getEmpName());

            if (TextUtils.isEmpty(userObject.getComId()) || userObject.getComId().equals("-1")) {//comId==null 或者 comId==-1 表示未加入企业
                check_my_apply.setVisibility(View.GONE);
                join_my_company.setVisibility(View.VISIBLE);
                ll_user_info.setVisibility(View.GONE);
                ll_departure.setVisibility(View.GONE);
                ll_apply_no_through.setVisibility(View.GONE);

                mLinearAddCompany.setVisibility(View.GONE);

            } else {//comId 不等于 -1 时 empStatus = -1 标识企业未确认，可查看申请公司   empStatus==1时 标示企业已确认
                //状态标识 0:审核不通过 1:已确认 -1:未确认 -2:已失效 -3:已退出
                if (userObject.getEmpStatus().equals("1")) {//企业已确认
                    mLinearAddCompany.setVisibility(View.VISIBLE);
                    mLinearContent.setBackgroundColor(getResources().getColor(R.color.normal_bg));
                    if (viewNoCompany != null) {
                        viewNoCompany.setVisibility(View.GONE);
                    }
                } else if (userObject.getEmpStatus().equals("-1")) {//企业未确认
                    mLinearAddCompany.setVisibility(View.GONE);
                    check_my_apply.setVisibility(View.VISIBLE);
                    join_my_company.setVisibility(View.GONE);
                    ll_user_info.setVisibility(View.VISIBLE);
                    ll_departure.setVisibility(View.GONE);
                    ll_apply_no_through.setVisibility(View.GONE);
                } else if (userObject.getEmpStatus().equals("0")) {//审核不通过
                    mLinearAddCompany.setVisibility(View.GONE);
                    check_my_apply.setVisibility(View.GONE);
                    join_my_company.setVisibility(View.GONE);
                    ll_user_info.setVisibility(View.VISIBLE);
                    ll_departure.setVisibility(View.GONE);
                    ll_apply_no_through.setVisibility(View.VISIBLE);
                }
            }

            if ((!TextUtils.isEmpty(userObject.getEmpType())) && userObject.getEmpType().equals("6")) {//离职
                mLinearAddCompany.setVisibility(View.GONE);
                check_my_apply.setVisibility(View.GONE);
                join_my_company.setVisibility(View.GONE);
                ll_user_info.setVisibility(View.VISIBLE);
                ll_departure.setVisibility(View.VISIBLE);
                ll_apply_no_through.setVisibility(View.GONE);
            }
        } else {
            mLinearAddCompany.setVisibility(View.GONE);
            if (viewNoCompany == null) {
                viewNoCompany = mViewStub.inflate();
            }
            viewNoCompany.setVisibility(View.VISIBLE);
            check_my_apply.setVisibility(View.GONE);
            join_my_company.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.company_image://公司
                PersonMessageComNameActivity.jump(getActivity(), userObject);
//                UserCompanyActivity.jump(getActivity(), userObject);
                break;
            case R.id.logo_name://公司
                PersonMessageComNameActivity.jump(getActivity(), userObject);
                break;
//            case R.id.team_empty://团队为空
//                getTeamInfo();
//                break;
            case R.id.head_empty://头条为空
                getHeadInfo();
                break;
            case R.id.mine_fuli_layout://我的福利
                MineWelfareActivity.jump(getActivity());
                break;
            case R.id.head_info_layout://同事头条
                if (inFoObjectsHead.size() > 0) {
                    createHeadInfoDilog(0);
                }
                break;
            case R.id.excitation_layout://团队激励
            case R.id.team_empty://团队激励
                ExcitationActivity0.jump(getActivity());
                break;
            case R.id.personLayout://用户中心
            case R.id.head_no_company:
            case R.id.user_image:
                if (userObject != null)
                    PersonMessageModifyActivity.jump(getActivity(), userObject);
                break;
            case R.id.look_my_reply://所申请加入的企业未确认
            case R.id.join_company_no_add_company://未加入企业
            case R.id.through_look_reply://所申请加入的企业未通过
                JoinCompanyActivity.jump(getActivity(), userObject);
                break;
            case R.id.departure_known://离职
                break;
        }
    }

    private void createHeadInfoDilog(int page) {
        ViewpagerDialog.Builder dialog = new ViewpagerDialog.Builder(getActivity());
        dialog.setData(inFoObjectsHead);
        dialog.show();
        dialog.showPage(page);
    }

    /**
     * 获取企业数
     */
    int comSize = 0;


    //获取公司列表(当comsize=1时取)
    private void getComList() {
        ExcitationPresenter.getInstance().getUserComAll(Globals.getToken(), new DataResponseListener<InfoArrayObject>() {
            @Override
            public void onSuccess(InfoArrayObject dataResponse) {
                companys.clear();
                companys.addAll(dataResponse.getInfo());
                comSize = companys.size();
                if (companys.size() == 1) {
                    CompanyConfirmActivity.jump(getActivity(), companys.get(0).getComId(), true);
                } else if (companys.size() > 1) {
                    CompanyListActivity.jump(getActivity(), 0);
                }
            }

            @Override
            public void onFail(String failMessage) {
                toast(failMessage);
            }

            @Override
            public void onError(Throwable e) {
                toast("网络或服务器异常！");
            }
        });
    }


    /**
     * 获取用户信息
     */
    private void getUserInfo() {
        LoadingUtils.createLoadingDialog(getActivity(), "正在获取...", true);
        try {
            ExcitationPresenter.getInstance().getUserInfo(Globals.getToken(), new DataResponseListener<UserObject>() {
                @Override
                public void onSuccess(UserObject dataResponse) {
                    userObject = dataResponse;
                    LoadingUtils.closeDialog();
                    if (userObject != null && !(userObject.getComId() == null || userObject.getComId().equals("-1") || userObject.getEmpStatus().equals("-1"))) {
                        SharedPreferencesUtils.saveExcitationUserId(userObject.getUserId(), getContext());
                        getHeadInfo();
                        getComConfig();
                        getWelfareMessage();
                    }
                    if (userObject.getComId().equals("-1")) {//加载列表接口
                        getComList();
                    }
                    initData();
                }

                @Override
                public void onFail(String failMessage) {
                    initData();
                    toast(failMessage);
                    LoadingUtils.closeDialog();
                }

                @Override
                public void onError(Throwable e) {
                    initData();
                    LoadingUtils.closeDialog();
                    toast("网络或服务器异常！");
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 获取同事头条
     */
    private void getHeadInfo() {

        ExcitationPresenter.getInstance().getHeadInfoList(Globals.getToken(), new DataResponseListener<BaseDataPageBody>() {
            @Override
            public void onSuccess(BaseDataPageBody dataResponse) {

                if (dataResponse.getInfo() == null || dataResponse.getInfo().size() == 0) {
                    if (inFoObjectsHead.size() == 0) {
                        headEmpty.setVisibility(View.VISIBLE);
                        headEmpty.setText("最近没有新鲜事哟~");
                    }
                } else {
                    if (headScrollViewAdapter == null) {
                        headScrollViewAdapter = new HeadScrollViewAdapter(getActivity(), inFoObjectsHead);
                        headautoScrollListView.setAdapter(headScrollViewAdapter);
                    }
                    inFoObjectsHead.clear();
                    inFoObjectsHead.addAll(dataResponse.getInfo());
                    headScrollViewAdapter.notifyDataSetChanged();
                    headEmpty.setVisibility(View.GONE);
                    if (inFoObjectsHead.size() <= 3) {
                        headautoScrollListView.stopAutoScroll();
                        headScrollViewAdapter.setScrollCount(inFoObjectsHead.size());
                    } else {
                        headautoScrollListView.startAutoScroll();
                        headScrollViewAdapter.setScrollCount(3);
                    }
                }
            }

            @Override
            public void onFail(String failMessage) {
                headEmpty.setText("加载失败，点击重新加载！");
                toast(failMessage);
            }

            @Override
            public void onError(Throwable e) {
                headEmpty.setText("加载失败，点击重新加载！");
                toast("网络或服务器异常！");
            }
        });
    }

    /**
     * 获取企业是否开启激励模块
     */
    private void getComConfig() {
        ExcitationPresenter.getInstance().getComConfig(Globals.getToken(), new DataResponseListener<BaseInfoBody>() {
            @Override
            public void onSuccess(BaseInfoBody dataResponse) {
                CompanyInfo companyInfo = (CompanyInfo) dataResponse.getInfo();
                if (companyInfo.isOpenAchieveAward()) {
                    getTeamInfo();
                    teamExcitationLayout.setVisibility(View.VISIBLE);
                } else {
                    teamExcitationLayout.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFail(String failMessage) {

            }

            @Override
            public void onError(Throwable e) {

            }
        });
    }

    /**
     * 获取团队激励消息列表
     */
    private void getTeamInfo() {
//        teamEmpty.setVisibility(View.VISIBLE);
//        teamEmpty.setText("加载中...");
        ExcitationPresenter.getInstance().getTeamEncourageList(Globals.getToken(), new DataResponseListener<BaseDataPageBody>() {
            @Override
            public void onSuccess(BaseDataPageBody dataResponse) {

                if (dataResponse.getInfo() == null || dataResponse.getInfo().size() == 0) {
                    if (inFoObjectsTeam.size() == 0) {
                        teamEmpty.setText("点赞墙空空，快去给同事点赞吧~");
                        autoScrollListView.setVisibility(View.GONE);
                        teamEmpty.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (autoAdapter == null) {
                        autoAdapter = new AutoScrollAdapter(inFoObjectsTeam);
                        autoScrollListView.setAdapter(autoAdapter);
                    }
                    inFoObjectsTeam.clear();
                    inFoObjectsTeam.addAll(dataResponse.getInfo());
                    autoAdapter.notifyDataSetChanged();
                    teamEmpty.setVisibility(View.GONE);
                    teamExcitationLayout.setVisibility(View.VISIBLE);
                    autoScrollListView.setVisibility(View.VISIBLE);
                    Log.e("列表长度", inFoObjectsTeam.size() + "");
                    if (inFoObjectsTeam.size() < 3) {
                        autoScrollListView.stopAutoScroll();
                        autoAdapter.setScrollCount(inFoObjectsTeam.size());
                    } else {
                        autoScrollListView.startAutoScroll();
                        autoAdapter.setScrollCount(3);
                    }
                }
            }

            @Override
            public void onFail(String failMessage) {
                toast(failMessage);
            }

            @Override
            public void onError(Throwable e) {
                toast("网络或服务器异常！");
            }
        });
    }

    /**
     * 显示消息
     */
    private void showViewFilper() {
        if (welfareMessageObjects.size() > 0) {
            viewFlipper.setVisibility(View.VISIBLE);
        } else {
            viewFlipper.setVisibility(View.GONE);
            return;
        }
        for (int i = 0; i < welfareMessageObjects.size(); i++) {
            final WelfareMessageObject welfareMessageObject = welfareMessageObjects.get(i);
            View view = getActivity().getLayoutInflater().inflate(R.layout.item_excition_message, null);
            final TextView textView = view.findViewById(R.id.text);
            textView.setText(welfareMessageObject.getWelfareName());
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    WebActivity.jump(getActivity(), welfareMessageObject.getH5Url());
                }
            });
            viewFlipper.addView(view);
            if (welfareMessageObjects.size() == 1) {//避免Viewfiper，只有一个item是动画异常
                View view0 = getActivity().getLayoutInflater().inflate(R.layout.item_excition_message, null);
                TextView textView0 = view0.findViewById(R.id.text);
                textView0.setText(welfareMessageObject.getWelfareName());
                textView0.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        textView.performClick();
                    }
                });
                viewFlipper.addView(view0);
            }
        }

    }

    @Override
    public void onStop() {
        super.onStop();
        if (viewFlipper != null && viewFlipper.isFlipping()) {
            viewFlipper.stopFlipping();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!LSWebHelper.getInstance().isUserLogined()) {//未登录返回商城页
            ((MainActivity0) getActivity()).changePage(0);
        } else {
//            getComeSize();
            getUserInfo();
            if (viewFlipper != null && !viewFlipper.isFlipping() && welfareMessageObjects.size() > 0) {
                viewFlipper.startFlipping();
            }
        }
    }
}
